#!/bin/bash 
#
# This Script made by haven200
# 23:36 21/01/2015
#
### BEGIN INIT INFO
# Provides:          hcsr
# Required-Start:    $all
# Required-Stop::    $all 
# Should-Start:      
# Should-Stop:       halt reboot
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

name="hcsr"
hcsr_py="/home/etc/python/$name.py"
hcsr_pid="/var/run/$name.pid"

. /lib/lsb/init-functions

make_dir() {

    if [ ! -d "$1" ]; then
        mkdir -p "$1"
    fi
}

do_start() {
    python "$hcsr_py" &
}

do_stop() {
    if [ -f "$hcsr_pid" ]; then 
        kill `cat $hcsr_pid`
        #rm "$hcsr_pid"
    fi 
}

case "$1" in
  start|"")
    log_daemon_msg "starting hcsr service...." "$name"
    do_start
    log_end_msg $?
    ;;
  restart|reload|force-reload)
    log_daemon_msg "stoping hcsr service...." "$name"
    do_stop
    log_end_msg $?
    log_daemon_msg "starting hcsr service...." "$name"
    do_start
    log_end_msg $?
    ;;
  stop)
    log_daemon_msg "stoping hcsr service...." "$scriptmount"
    do_stop
    log_end_msg $?
    ;;
  *)
    log_action_msg "Usage: service $name {start|stop|restart|reload|force-reload}"
    exit 2
    ;;
esac

exit 0
